<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <title>OpenLayers Accelerometer Usage</title>
    <link rel="stylesheet" href="../theme/default/style.css" type="text/css">
    <link rel="stylesheet" href="style.css" type="text/css">
    <script type="text/javascript" src="browser.js"></script>

    <style type="text/css">
        .olControlAttribution {
            bottom: 5px;
        }
    </style>
    <script type="text/javascript">
        function init() {
            if (isEventSupported('deviceorientation', window) || isEventSupported('mozorientation', window) || isEventSupported('devicemotion', window)) {
                if (window.DeviceOrientationEvent) {
                    window.addEventListener("deviceorientation", function (event) {
                        document.getElementById('resultDeviceOrientation').innerHTML = '';
                        if (typeof(event.alpha) != 'undefined') {
                            document.getElementById('resultDeviceOrientation').innerHTML = document.getElementById('resultDeviceOrientation').innerHTML + "Alpha: " + event.alpha + "<br>";
                            document.getElementById('resultDeviceOrientation').innerHTML = document.getElementById('resultDeviceOrientation').innerHTML + "Beta: " + event.beta + "<br>";
                            document.getElementById('resultDeviceOrientation').innerHTML = document.getElementById('resultDeviceOrientation').innerHTML + "Gamma: " + event.gamma + "<br>";
                        }
                        if (typeof(event.absolute) != 'undefined') {
                            document.getElementById('resultDeviceOrientation').innerHTML = document.getElementById('resultDeviceOrientation').innerHTML + "Gamma: " + event.absolute + "<br>";
                        }
                        if (typeof(event.compassCalibrate) != 'undefined') {
                            document.getElementById('resultDeviceOrientation').innerHTML = document.getElementById('resultDeviceOrientation').innerHTML + "Gamma: " + event.compassCalibrated + "<br>";
                        }
                    }, true);
                }
                if (window.DeviceMotionEvent) {
                    window.addEventListener('devicemotion', function (event) {
                        document.getElementById('resultDeviceMotion').innerHTML = '';
                        if (typeof(event.accelerationIncludingGravity) != 'undefined') {
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "accelerationIncludingGravity.x: " + event.accelerationIncludingGravity.x + "<br>";
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "accelerationIncludingGravity.y: " + event.accelerationIncludingGravity.y + "<br>";
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "accelerationIncludingGravity.z: " + event.accelerationIncludingGravity.z + "<br>";
                        }
                        if (typeof(event.acceleration) != 'undefined') {
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "acceleration.x: " + event.acceleration.x + "<br>";
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "acceleration.y: " + event.acceleration.y + "<br>";
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "acceleration.z: " + event.acceleration.z + "<br>";
                        }
                        if (typeof(event.rotationRate) != 'undefined') {
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "rotationRate.alpha: " + event.rotationRate.alpha + "<br>";
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "rotationRate.beta: " + event.rotationRate.beta + "<br>";
                            document.getElementById('resultDeviceMotion').innerHTML = document.getElementById('resultDeviceMotion').innerHTML + "rotationRate.gamma: " + event.rotationRate.gamma + "<br>";
                        }
                    }, true);
                }
                if (window.MozOrientation) {
                    window.addEventListener("MozOrientation", function (orientation) {
                        document.getElementById('resultMozOrientation').innerHTML = "orientation.x: " + orientation.x + "<br>";
                        document.getElementById('resultMozOrientation').innerHTML = document.getElementById('resultMozOrientation').innerHTML + "orientation.y: " + orientation.y + "<br>";
                        document.getElementById('resultMozOrientation').innerHTML = document.getElementById('resultMozOrientation').innerHTML + "orientation.z: " + orientation.z + "<br>";
                    }, true);
                }
            } else {
                alert("Unfortunately, your brower doesn't support the orientation usage");
            }

        }
    </script>
</head>
<body onload="init()">
<h1 id="title">Accelerometer</h1>

<p id="shortdesc">
    The goal of this script is to demonstrate the usage of accelerometer.
</p>
<p>
  The orientation specification can be found <a href="http://dev.w3.org/geo/api/spec-source-orientation.html">here</a>.
</p>

<div id="tags">
  browser, vendor, mobile, orientation 
</div>  

<h1>Device motion</h1>

<div id="resultDeviceMotion">

</div>
<h1>Device orientation</h1>

<div id="resultDeviceOrientation">

</div>
<h1>MOZ orientation</h1>

<div id="resultMozOrientation">

</div>
</body>
</html>
